package com.example.controller;

import com.example.common.Result;
import com.example.entity.MapCheckPoint;
import com.example.service.MapCheckPointService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 关卡前端接口
 */
@RestController
@RequestMapping("/mapcheckpoint")
public class MapCheckPointController {

    @Resource
    private MapCheckPointService mapcheckpointService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody MapCheckPoint mapcheckpoint) {
        mapcheckpointService.add(mapcheckpoint);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        mapcheckpointService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        mapcheckpointService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody MapCheckPoint mapcheckpoint) {
        mapcheckpointService.updateById(mapcheckpoint);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        MapCheckPoint mapcheckpoint = mapcheckpointService.selectById(id);
        return Result.success(mapcheckpoint);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(MapCheckPoint mapcheckpoint ) {
        List<MapCheckPoint> mapcheckpointList = mapcheckpointService.selectAll(mapcheckpoint);
        return Result.success(mapcheckpointList);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(MapCheckPoint mapcheckpoint,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<MapCheckPoint> pageInfo = mapcheckpointService.selectPage(mapcheckpoint, pageNum, pageSize);
        return Result.success(pageInfo);
    }

}
